using System;
using L=Science.Physics.GeneralPhysics;

namespace Serway.Chapter28
{
	/// <summary>
	/// Example10: A Multiloop Circuit
	/// (A)	
	/// Under steady-state conditions, find the unknown currents I_1, I_2 
	/// and I_3 in the multiloop circuit shown in Figure 28.18.
	/// (B)	
	/// What is the charge on the capacitor?
	/// </summary>
	public class Example10
	{
		public Example10()
		{
		}
		private string result;
		public string Result
		{
			get{return result;}
		}
		public void Compute()
		{
			L.Circuit cir = new L.Circuit();

			cir.NumberOfJunctions = 2;
			L.ElectricPotential[] V = new L.ElectricPotential[2];
			V[0] = new L.ElectricPotential();
			V[0].V = 0.0;
			V[1] = new L.ElectricPotential();
			V[1].VariableQ = true;
			cir.PotentialAtJunction = V;

			cir.NumberOfSegments = 3;
			L.ElectricCurrent[] I = new L.ElectricCurrent[3];
			I[0] = new L.ElectricCurrent();
			I[0].VariableQ = true;
			I[0].FromJunction = 1;
			I[0].ToJunction = 0;
			I[1] = new L.ElectricCurrent();
			I[1].VariableQ = true;
			I[1].FromJunction = 1;
			I[1].ToJunction = 0;
			I[2] = new L.ElectricCurrent();
			I[2].VariableQ = true;
			I[2].FromJunction = 0;
			I[2].ToJunction = 1;
			cir.Current = I;

			cir.Segment = 0;
			L.ElectricPotentialDifference v1 
				= new L.ElectricPotentialDifference();
			v1.V = 8.0;
			L.Resistance r1 = new L.Resistance();
			r1.Ohm = 5.0;
			cir.Add(v1);
			cir.Add(r1);

			cir.Segment = 1;
			L.Resistance r3 = new L.Resistance();
			r3.Ohm = 3.0;
			cir.Add(r3);

			cir.Segment = 2;
			L.ElectricPotentialDifference v2 
				= new L.ElectricPotentialDifference();
			v2.V = 4.0;
			L.Resistance r2 = new L.Resistance();
			r2.Ohm = 5.0;
			cir.Add(v2);
			cir.Add(r2);

			cir.KirchhoffRule();

			result += Convert.ToString(I[0].A)+"  "+
				Convert.ToString(I[1].A)+"  "+
				Convert.ToString(I[2].A)+"\r\n";
		}
	}
}
